//
//  MakefirendsReleaseTwoCell.m
//  cityStar
//
//  Created by joyban on 15-1-26.
//  Copyright (c) 2015年 tiny. All rights reserved.
//

#import "MakefirendsReleaseTwoCell.h"

@implementation MakefirendsReleaseTwoCell

+(CGFloat)heightOfTableCell
{
    return 352;
}

- (void)awakeFromNib {
    self.EducationText.delegate = self;
    self.MonthlySalaryText.delegate = self;
    self.carText.delegate = self;
    self.RequirementText.delegate = self;
    self.QQText.delegate = self;
    self.WeChatText.delegate = self;
    self.educationType = [NSString stringWithFormat:@"%i",0];
    self.monthlySalaryType = @"0";
    self.haveCarType = @"0";
    self.arrsyEducation = [NSArray arrayWithObjects:@"小学及以下",
                           @"初中",
                           @"高中",
                           @"中专",
                           @"大专",
                           @"本科",
                           @"硕士",
                           @"博士",
                           @"留学",nil];
    self.arrsymonthlySalary = [NSArray arrayWithObjects:@"3000 以下",
                           @"3000-5000",
                           @"5000-8000",
                           @"8000-15000",
                           @"15000-20000",
                           @"20000-40000",
                           @"40000-100000",
                           @"100000+",
                           @"我有公司",nil];
    self.arrsyhaveCar = [NSArray arrayWithObjects:@"无房无车",
                               @"有车无房",
                               @"有房有车",
                               nil];
    
    UIPickerView *educationPickerView = [[UIPickerView alloc]init];
    educationPickerView.delegate = self;
    educationPickerView.tag = 0;
    self.EducationText.inputView = educationPickerView;
    
    UIPickerView *monthPickerView = [[UIPickerView alloc]init];
    monthPickerView.delegate = self;
    monthPickerView.tag = 1;
    self.MonthlySalaryText.inputView = monthPickerView;
    
    UIPickerView *haveCarPickerView = [[UIPickerView alloc]init];
    haveCarPickerView.delegate = self;
    haveCarPickerView.tag = 2;
    self.carText.inputView = haveCarPickerView;
    
    UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
    [topView setBarStyle:UIBarStyleDefault];
    
    UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    
    NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace,doneButton,nil];
    
    [topView setItems:buttonsArray];
    [self.EducationText setInputAccessoryView:topView];
    [self.MonthlySalaryText setInputAccessoryView:topView];
    [self.carText setInputAccessoryView:topView];
}

-(void)dismissKeyBoard
{
    [self.EducationText resignFirstResponder];
    [self.MonthlySalaryText resignFirstResponder];
    [self.carText resignFirstResponder];
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    switch (textField.tag) {
        case 1:
            textField.text = @"小学及以下";
            break;
        case 3:
            textField.text = @"3000 以下";
            break;
        case 4:
            textField.text = @"无房无车";
            break;
            
        default:
            break;
    }
}

#pragma mark - pickerViewDelegate
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (pickerView.tag == 0) {
        return self.arrsyEducation.count;
    }else if(pickerView.tag == 1){
        return self.arrsymonthlySalary.count;
    }else{
        return self.arrsyhaveCar.count;
    }
}

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (pickerView.tag == 0) {
        return self.arrsyEducation[row];
    }else if(pickerView.tag == 1){
        return self.arrsymonthlySalary[row];
    }else{
        return self.arrsyhaveCar[row];
    }
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView.tag == 0) {
        self.EducationText.text = self.arrsyEducation[row];
        self.educationType = [NSString stringWithFormat:@"%li",(long)row];
    }else if(pickerView.tag == 1){
        self.MonthlySalaryText.text = self.arrsymonthlySalary[row];
        self.monthlySalaryType = [NSString stringWithFormat:@"%li",(long)row+1];
    }else{
        self.carText.text = self.arrsyhaveCar[row];
        self.haveCarType = [NSString stringWithFormat:@"%li",(long)row];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

@end
